﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Common.Tools
{
    public class LogHelper
    {
        public static void WriteLine(string info,string filename)
        {
            StreamWriter streamWriter = null;//文件写入流
            FileStream fileStream = null;
            string mPath = Application.StartupPath + "\\"+filename;//+DateTime.Now.ToString("yyyyMMdd")+".txt\\";
            //文件不存在时
            if (!File.Exists(@mPath))
            {
                try
                {
                    fileStream = File.Create(@mPath);
                }
                catch (Exception)
                {
                    return;

                }
                finally
                {
                    if (fileStream == null) { }
                    else
                    {
                        fileStream.Close(); //关闭文件流
                    }
                }

            }
            streamWriter = new StreamWriter(@mPath, true, Encoding.UTF8);

            try
            {
                streamWriter.WriteLine(info);
            }
            catch (Exception)
            {

            }
            finally
            {
                streamWriter.Close();
            }
        }
    }
}
